﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;

namespace EasyTask.EasyHelper
{
    /// <summary>
    /// 枚举帮助类类
    /// </summary>
    public class EnumHelper
    {
        /// <summary>
        /// 返回枚举项的描述信息。
        /// </summary>
        /// <param name="value">要获取描述信息的枚举项。</param>
        /// <returns>枚举想的描述信息。</returns>
        public static string GetDescription(Enum value)
        {
            return value.GetType()
        .GetMember(value.ToString())
        .FirstOrDefault()?
        .GetCustomAttribute<DescriptionAttribute>()?
        .Description;
        }
    }
}
